import json
import time
from .getPublicData import *


def getPieBrandData():
    cars=list(getAllCars())
    carsVolume={}
    for i in cars:
        # 检查 carmodel 是否不在字典中
        if i.brand not in carsVolume:
            carsVolume[i.brand] = int(i.salevolume)
        else:
            carsVolume[i.brand] += int(i.salevolume)


    carsVolume=sorted(zip(carsVolume.values(), carsVolume.keys()), reverse=True)
    lastsortlist = []
    sortDict = {i[1]: i[0] for i in carsVolume}
    for k, v in sortDict.items():
        lastsortlist.append({
            'name': k,
            'value': v
        })
    print(lastsortlist)

    return lastsortlist[:10]


